package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.PropertyHelper;

@Cmd(code = Protocol.S_DOU_LUO_DA_LU_BUFF_BUY_FROM_CROSS,desc = "Buff购买")
public class DouLuoDaLuBuyBattleBuffCmdFromCross extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        DouLuoDaLuProto.DouLuoDaLuBuyBattleBuffCrossRespMsg crossRespMsg = DouLuoDaLuProto.DouLuoDaLuBuyBattleBuffCrossRespMsg.parseFrom(packet.getBytes());

        player.getModule(PreReduceModule.class).restorePreReduce(crossRespMsg.getConsume());

        if(crossRespMsg.getRet() == 0){
            player.getModule(CurrencyModule.class).removeCurrency(PropertyHelper.parseStringToProperty(crossRespMsg.getConsume()),
                    eLogMoneyType.DouLuoDaLuActivity, eLogMoneyType.DouLuoDaLuBuyBuffConsume);
        }

        DouLuoDaLuProto.DouLuoDaLuBuyBattleBuffRespMsg.Builder resp = DouLuoDaLuProto.DouLuoDaLuBuyBattleBuffRespMsg.newBuilder();
        resp.setRet(crossRespMsg.getRet());
        if(crossRespMsg.hasPatrons()){
            resp.setPatrons(crossRespMsg.getPatrons());
        }
        if(crossRespMsg.hasAddition()){
            resp.setAddition(crossRespMsg.getAddition());
        }
        player.sendPacket(Protocol.U_DOU_LUO_DA_LU_BUFF_BUY, resp);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
